//package com.ums.upos;
//
//import android.content.ComponentName;
//import android.content.Context;
//import android.content.Intent;
//import android.content.ServiceConnection;
//import android.os.Bundle;
//import android.os.IBinder;
//import android.os.RemoteException;
//import android.support.test.InstrumentationRegistry;
//import android.support.test.filters.LargeTest;
//import android.support.test.rule.ServiceTestRule;
//import android.support.test.runner.AndroidJUnit4;
//import android.util.Log;
//
//import com.nexgo.oaf.apiv3.card.mifare.AuthEntity;
//import com.ums.upos.service.DeviceServiceEngineService;
//import com.ums.upos.uapi.card.mifare.M1CardHandler;
//import com.ums.upos.uapi.card.mifare.M1KeyTypeConstrants;
//import com.ums.upos.uapi.device.reader.icc.IccCardReader;
//import com.ums.upos.uapi.device.reader.icc.IccCardType;
//import com.ums.upos.uapi.device.reader.icc.IccReaderSlot;
//import com.ums.upos.uapi.device.reader.icc.OnSearchIccCardListener;
//import com.ums.upos.uapi.engine.DeviceServiceEngine;
//
//import org.junit.After;
//import org.junit.AfterClass;
//import org.junit.Before;
//import org.junit.Rule;
//import org.junit.Test;
//import org.junit.runner.RunWith;
//
///**
// * Created by Administrator on 2017/3/31.
// */
//
//@RunWith(AndroidJUnit4.class)
//@LargeTest
//public class M1CardServiceTest{
//    //    private static DeviceServiceEngine mDeviceHandle = null;
//    private static IccCardReader reader = null;
//    private static M1CardHandler m1CardHandler  = null;
//    private DeviceServiceEngine mDeviceHandle = null;
//    private byte[] m1SN;
//
//    @Rule
//    public ServiceTestRule mServiceRule = new ServiceTestRule();
//
//    private OnSearchIccCardListener listener= new OnSearchIccCardListener.Stub(){
//        @Override
//        public void onSearchResult(int retCode, Bundle bundle) throws RemoteException {
//            Log.d("Result--------",retCode+"");
//            if(retCode==0){
//                reader.stopSearch();
//                String cardtype = bundle.getString("CardType");
//                Log.d("cardtype卡类型",cardtype+"");
//                m1SN = bundle.getByteArray("m1_sn");
//            }
//        }
//    };
//    @AfterClass
//    public static void afterall() throws InterruptedException {
//        Thread.sleep(10 * 1000, 0);
//    }
//
//    @After
//    public void afrer() throws InterruptedException {
//        Thread.sleep(10 * 1000, 0);
//    }
//
//    @Before
//    public void start() {
//        Log.d("Test------------","单元测试启动");
//
//        if (null == reader) {
//            ServiceConnection conn = new ServiceConnection() {
//
//                @Override
//                public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
//                    mDeviceHandle = DeviceServiceEngine.Stub.asInterface(iBinder);
//
//                }
//
//                @Override
//                public void onServiceDisconnected(ComponentName componentName) {
//                    reader = null;
//                    m1CardHandler = null;
//                }
//            };
//            Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), DeviceServiceEngineService.class);
//            try {
//                mServiceRule.bindService(intent, conn, Context.BIND_AUTO_CREATE);
//                Bundle loginBundle = new Bundle();
//                loginBundle.putInt("workMode", 0);
//                mDeviceHandle.login(loginBundle, "00000001");
//                reader=mDeviceHandle.getIccCardReader(IccReaderSlot.RFSlOT);
//                m1CardHandler = mDeviceHandle.getM1CardHandler(reader);
//                try {
//                    Thread.sleep(10 * 1000, 0);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//
//            } catch (Exception e) {
//                reader = null;
//                m1CardHandler = null;
//                e.printStackTrace();
//            }
//
//        }
//
//    }
//    @Test
//    public void test_QueryCard() {
//        Log.d("test_QueryCard","test_QueryCard开始");
//        try {
//            reader.searchCard(listener,3000, new String[]{IccCardType.M1CARD});
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//    @Test
//    public void test_authority() {
//        Log.d("test_authority","test_authority开始");
//        try {
//            if(null!=m1CardHandler) {
//                int blkNo = 0;
//                byte[] pwd = new byte[6];
//                pwd[0] = (byte) 0xff;
//                pwd[1] = (byte) 0xff;
//                pwd[2] = (byte) 0xff;
//                pwd[3] = (byte) 0xff;
//                pwd[4] = (byte) 0xff;
//                pwd[5] = (byte) 0xff;
//
//                int authority = m1CardHandler.authority(M1KeyTypeConstrants.KEYTYPE_A, blkNo, pwd, m1SN);
//                Log.d("authority", authority + "----------");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//}
